/*
 * @Author: Eureka 
 * @Date: 2022-01-19 11:46:56 
 * @Last Modified by: Eureka
 * @Last Modified time: 2022-01-21 11:44:57
 */

import 'package:flutter/cupertino.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:senkoo_platform/Utils/base_standard.dart';
import 'package:senkoo_platform/Utils/base_text.dart';
import 'package:senkoo_platform/Utils/hex_color_utils.dart';
import 'package:senkoo_platform/Utils/set_edge_insets.dart';
import 'package:senkoo_platform/base_image/image_utils.dart';
import 'package:senkoo_platform/base_import/base_import.dart';
import 'package:senkoo_platform/base_router/base_router_util.dart';
import 'package:senkoo_platform/views/equipment_modular/equipment_page.dart';
import 'package:senkoo_platform/views/history_modular/history_page.dart';
import 'package:senkoo_platform/views/login_modular/login_page.dart';
import 'package:senkoo_platform/views/monitor_modular/monitor_page.dart';
import 'package:senkoo_platform/views/operate_modular/operate_page.dart';
import 'package:senkoo_platform/views/screen_modular/screen_page.dart';

class MainPage extends StatefulWidget {
  const MainPage({
    super.key,
  });

  @override
  State<MainPage> createState() => _MainPageState();
}

class _MainPageState extends State<MainPage> {
  int _selectedIndex = 0;

  List modularList = [
    {'index': 0, 'page': const EquipmentPage()},
    {'index': 1, 'page': const OperatePage()},
    {'index': 2, 'page': const MonitorPage()},
    {'index': 3, 'page': const HistoryPage()},
    {'index': 4, 'page': const ScreenPage()},
  ];

  @override
  Widget build(BuildContext context) => AnnotatedRegion(
        value: SystemUiOverlayStyle.light,
        child: Container(
          color: HexColor('#101423'),
          padding: setAllEdgeInsets(all: 40),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Container(
                width: 166.w,
                height: 50.h,
                decoration: BoxDecoration(
                    image: DecorationImage(
                  image: ImageUtils.getAssetImage("hdl_logo_name"),
                )),
              ),
              Expanded(
                  child: Container(
                color: Colors.transparent,
                child: Row(
                  children: [leftWidget(), rightWidget()],
                ),
              ))
            ],
          ),
        ),
      );

  Widget textWidget(String string) => text(
        textString: string,
        textColor: Standard.colorFFFFFF,
        textSize: 12.sp,
      );

  Widget leftWidget() => NavigationRail(
        useIndicator: true,
        elevation: 1,
        selectedIndex: _selectedIndex,
        trailing: Expanded(
          child: Align(
            alignment: Alignment.bottomCenter,
            child: Padding(
              padding: const EdgeInsets.only(bottom: 0),
              child: GestureDetector(
                onTap: () {
                  RouterUtil.pushRemovePage(context, LoginPage());
                },
                child: const FlutterLogo(),
              ),
            ),
          ),
        ),
        onDestinationSelected: (int index) {
          setState(() {
            _selectedIndex = index;
          });
        },
        labelType: NavigationRailLabelType.all,
        backgroundColor: HexColor('#101423'),
        destinations: <NavigationRailDestination>[
          NavigationRailDestination(
            icon: Icon(
              Icons.favorite_border,
              size: 40.w,
            ),
            selectedIcon: Icon(
              Icons.favorite,
              size: 40.w,
            ),
            label: textWidget("配置数据"),
          ),
          NavigationRailDestination(
            icon: Icon(
              Icons.person_outline_rounded,
              size: 40.w,
            ),
            selectedIcon: Icon(
              Icons.person,
              size: 40.w,
            ),
            label: textWidget('运营操作'),
          ),
          NavigationRailDestination(
            icon: Icon(
              Icons.shopping_cart_outlined,
              size: 40.w,
            ),
            selectedIcon: Icon(
              Icons.shopping_cart,
              size: 40.w,
            ),
            label: textWidget('实时监控'),
          ),
          NavigationRailDestination(
            icon: Icon(
              Icons.shopping_cart_outlined,
              size: 40.w,
            ),
            selectedIcon: Icon(
              Icons.shopping_cart,
              size: 40.w,
            ),
            label: textWidget('历史数据'),
          ),
          NavigationRailDestination(
            icon: Icon(
              Icons.shopping_cart_outlined,
              size: 40.w,
            ),
            selectedIcon: Icon(
              Icons.shopping_cart,
              size: 40.w,
            ),
            label: textWidget('大屏展示'),
          ),
        ],
        selectedIconTheme: IconThemeData(color: Colors.white, size: 40.w),
        unselectedIconTheme: IconThemeData(
          color: Standard.colorFFFFFF,
        ),
        indicatorColor: HexColor('#1C3EF3'),
        indicatorShape: const CircleBorder(),
      );

  Widget rightWidget() => Expanded(
        child: Container(
          decoration: BoxDecoration(
              borderRadius: BorderRadius.circular(24.r),
              gradient: const LinearGradient(
                colors: [Color(0xFF101423), Color(0xFF171D34)],
                begin: Alignment.centerRight,
                end: Alignment.centerLeft,
              )),
          child: modularList[_selectedIndex]['page'],
        ),
      );
}
